<template>
	<view class="shenShop">
		<view class="shenShop_count">
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					真实姓名
				</view>
				<view class="shenShop_one_right">
					<input type="text" v-model="params.name" placeholder="姓名">
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					身份证号
				</view>
				<view class="shenShop_one_right">
					<input type="text" v-model="params.idnumber" placeholder="请输入身份证号">
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
			<view class="shenShop_three">
				<view class="shenShop_one_left">
					证件图片
				</view>
				<view class="shenShop_three_image">
					<view class="image_one" @click="upzhengshu('front')">
						<image v-if="!params.front_image" src="../../../static/images/upShenfen.png" mode="aspectFill"></image>
						<image v-if="params.front_image" :src="params.front_image" mode="aspectFill"></image>
					</view>
					<view class="image_one" @click="upzhengshu('back')">
						<image v-if="!params.back_image" src="../../../static/images/upShenfen_F.png" mode="aspectFill"></image>
						<image v-if="params.back_image" :src="params.back_image" mode="aspectFill"></image>
					</view>
				</view>
			</view>
			<div v-if="status==2" style="font-size: 26rpx;color: red;box-sizing: border-box;padding: 25rpx 0;">驳回原因：{{remark}}</div>
		</view>
		<!-- 按钮 -->
		<view class="shenShop_button">
			<view class="shenShop_one" v-if="status==0">
				审核中
			</view>
			<view class="shenShop_one" v-else-if="status==1">
				审核通过
			</view>
			<view class="shenShop_one" v-else-if="status==2" @click="confirmShop">
				审核失败，请重新提交
			</view>
			<view class="shenShop_one" v-else @click="confirmShop">
				提交
			</view>
		</view>
		<wanl-address ref='wanlAddress' @selectAddress="successSelectAddress"></wanl-address>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				params:{
					name:"",
					idnumber:"",
					front_image:"",
					back_image:"",
				},
				remark:"",
				status:-1,
			}
		},
		onLoad() {
			this.getshopInfo()
		},
		methods:{
			btnClick() {
				this.$refs.wanlAddress.show()
			},
			successSelectAddress(address) {
				console.log(address)
				this.params.city=address.formatted_address
			},
			upzhengshu(type){
				uni.chooseImage({
					count:1,
					success: (res) => {
						// console.log(res,'899999')
						this.uploadFile(res.tempFilePaths[0],type)
					}
				})
			},
			uploadFile(file,type) {
				uni.request({
					url: '/wanlshop/common/uploadData',
					success: updata => {
						uni.uploadFile({
							url: updata.data.uploadurl,
							filePath: file,
							name: 'file',
							formData: updata.data.storage == 'local' ? null : updata.data.multipart,
							success: res => {
								// console.log('上传成功',res.data)
								var data =JSON.parse(res.data)
								if(type=='front'){
									this.params.front_image=data.data.fullurl
								}else{
									this.params.back_image=data.data.fullurl
								}
							},
							fail: error => {
								this.$wanlshop.msg(JSON.parse(error.data).msg);
							}
						});
					}
				});
			},
			async getshopInfo(){
				await uni.request({
					url:"/wanlshop/card/card_info",
					method:"POST",
					data:{},
					success: (res) => {
						if(res.data){
							this.params.name=res.data.name
							this.params.idnumber=res.data.idnumber
							this.params.front_image=res.data.front_image
							this.params.back_image=res.data.back_image
							this.status=res.data.status
							this.remark=res.data.remark
						}
						// console.log(res.data,'身份详情')
					}
				})
			},
			async confirmShop(){
				if(!this.params.name) return this.$wanlshop.msg('请输入真实姓名')
				if(!this.params.idnumber) return this.$wanlshop.msg('请输入身份证号')
				if(!this.params.front_image) return this.$wanlshop.msg('请上传身份证正面')
				if(!this.params.back_image) return this.$wanlshop.msg('请上传身份证反面')
				await uni.request({
					url:"/wanlshop/card/auth",
					method:"POST",
					data:this.params,
					success: (res) => {
						this.$wanlshop.msg('提交成功')
						this.getshopInfo()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shenShop{
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx 24rpx 150rpx;
		.shenShop_count{
			width: 100%;
			background-color: #ffffff;
			box-sizing: border-box;
			padding: 0 20rpx;
			border-radius: 20rpx;
			.shenShop_one{
				width: 100%;
				height: 100rpx;
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #f7f7f7;
				.shenShop_one_left{
					width: 140rpx;
					font-size: 30rpx;
					color: #333333;
					font-weight: 800;
				}
				.shenShop_one_right{
					flex: 1;
					display: flex;
					align-items: center;
					input{
						flex: 1;
						height: 100rpx;
						font-size: 28rpx;
						text-align: right;
					}
				}
			}
			// 店铺头像
			.shenShop_two{
				height: 140rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1rpx solid #f7f7f7;
				.shenShop_one_left{
					width: 140rpx;
					font-size: 30rpx;
					color: #333333;
					font-weight: 800;
				}
				.shenShop_one_right{
					display: flex;
					align-items: center;
					image{
						width: 100rpx;
						height: 100rpx;
						border-radius: 10rpx;
					}
				}
			}
			// 身份正好
			.shenShop_three{
				width: 100%;
				box-sizing: border-box;
				padding: 30rpx 0;
				border-bottom: 1rpx solid #f7f7f7;
				.shenShop_one_left{
					width: 140rpx;
					font-size: 30rpx;
					color: #333333;
					font-weight: 800;
				}
				.shenShop_three_image{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-around;
					margin-top: 55rpx;
					.image_one{
						image{
							width: 303rpx;
							height: 180rpx;
							border: 1rpx solid #f7f7f7;
						}
					}
				}
			}
		}
		.shenShop_button{
			width: 100%;
			height: 140rpx;
			background-color: #ffffff;
			position: fixed;
			left: 0;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			.shenShop_one{
				width: 80%;
				height: 90rpx;
				line-height: 90rpx;
				text-align: center;
				background-color: #fe6600;
				border-radius: 45rpx;
				font-size: 30rpx;
				color: #ffffff;
			}
			
		}
	}
</style>